#ifndef PINYINIME_INCLUDE_KEYMAPPING_H__
#define PINYINIME_INCLUDE_KEYMAPPING_H__

#include <stdio.h>
#include <stdlib.h>
#include "./dictdef.h"
#include "./splparser.h"

namespace ime_pinyin {


struct KeyMappingNode{
	uint32 spelling_idx:12;
	uint32 keymapping_value : 20;
};

class KeyMapping {
public:

	//default one is a bellpad keymapping
	KeyMapping();
	~KeyMapping();

	// get mapping
	const char * key_to_chars(char key);
	//
	char char_to_key(char ch);

	char * spl_id_to_keys(uint16 splid);
	char * spl_to_keys(const char * spl);

	//whether the key is mapped
	bool is_mapped_key(char key);

	//whether the char is a mapping character
	bool is_mapping_char(char ch);

	bool is_splitter( const char c );

	bool is_valid_to_parse(char ch);

	bool construct_key_mapping_table();

	uint16 * get_mapped_spl_idxs(const char * keys, int keys_len, uint16 * spl_idx_buf, int max_size, int * spl_idx_num);

	size_t get_pinyin_from_keys( const char* keys, char* outBuf, int outBufSize, SpellingParser* spl_parser_ );

	size_t append_split_info( const char *rawkeys, char* pinyin, int pinyinbuf_length );

	size_t sort_by_sorce( char* pinyinBuf, size_t buf_length );

private:
	enum strType
	{
		NUM_STR = 1,
		PINYIN_STR,
		MIX_STR //there are pinyin and number in the str
	};
	typedef int STR_TYPE;
	STR_TYPE mCurrentStrType;
	char* mpInputBuf;

	uint32 str_to_uint( const char* str );

	char abc_char( const char c );
	bool py_equal( const char* input, const char* data_from_base );
	bool contain_split( const char* input, bool contain_last_char );
	int get_mapped_spl_idxs_core( uint32 value, uint16 * spl_idx_buf, int bufSize );

private :
	static const int kMaxTableSize 		= 512;
	static const int kMaxMappingPerKey	= 10;

	static const int kBellPadKeyNum		= 8;
	static const char kBellPadKeys[kBellPadKeyNum];// = {'2', '3', '4', '5', '6', '7', '8', '9'};
	static const char kBellPadMapping[kBellPadKeyNum][kMaxMappingPerKey+1];/* = {
			"",			// 0 key
			"",			// 1 key
			"ABC",		// 2 key
			"DEF",		// 3 key
			"GHI",		// 4 key
			"JKL",		// 5 key
			"MNO",		// 6 key
			"PQRS",		// 7 key
			"TUV",		// 8 key
			"WXYZ"		// 9 key
	};
*/
	// default mapping is null
//	static const char kDefaultMapping[kMaxMappingPerKey+1]={'\0'};
	KeyMappingNode * table_;
	int				 table_size;
};

}

#endif
